package com.dou.sample.opengl_project.data;

import com.dou.sample.opengl_project.objects.ObjectBuilder;
import com.dou.sample.opengl_project.shader.ColorShaderProgram;
import com.dou.sample.opengl_project.utls.GeoMetry;

import java.util.List;

/**
 * Created by Dou on 2018/1/16.
 */

public class Mallet {

    private static final int POSITION_COMPONENT_COUNT = 3;

    public float radius;
    public float height;

    private VertexArray vertexArray;
    private List<ObjectBuilder.DrawCommand> drawList;

    public Mallet(float radius, float height, int numPoint){

        ObjectBuilder.GenerateData generateData = ObjectBuilder.createMallet(new GeoMetry.Point(0, 0, 0), radius, height, numPoint);

        this.radius = radius;
        this.height = height;

        vertexArray = new VertexArray(generateData.vertexData);
        drawList = generateData.drawList;
    }

    public void bindData(ColorShaderProgram colorShaderProgram){
        // 绑定数据
        vertexArray.setVertexAttributePointer(
                0,
                colorShaderProgram.getaPositionLocation(),
                POSITION_COMPONENT_COUNT,
                0
                );
    }

    public void draw(){
        for (ObjectBuilder.DrawCommand drawCommand : drawList){
            drawCommand.draw();
        }
    }
}
